﻿<UserControl x:Class="System.Windows.Controls.AnalogGauge"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:System.Windows.Controls"
             mc:Ignorable="d" 
             d:DataContext="{d:DesignInstance local:AnalogGauge,IsDesignTimeCreatable=True}"
             x:Name="self"
             Width="300"
             Height="300"
             d:DesignHeight="300" d:DesignWidth="300" Loaded="UserControlLoaded">
    <Grid x:Name="_grid">
        <Border Background="{Binding BaseBackground}" BorderBrush="{Binding Path=BezelBackground}" BorderThickness="{Binding Path=BezelThickness}" CornerRadius="{Binding Path=BezelCornerRadius}">
            <Border.Effect>
                <DropShadowEffect Direction="320" Opacity="0.5" ShadowDepth="5" Color="Black"></DropShadowEffect>
            </Border.Effect>
        </Border>
        <Path Stroke="{Binding Path=ScaleBackground}" StrokeThickness="{Binding Path=ScaleBackgroundThickness}">
            <Path.Data>
                <PathGeometry Figures="{Binding Path=ScaleData}"/>
                
            </Path.Data>
        </Path>
        <ItemsControl ItemsSource="{Binding Path=Ranges}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas Background="Transparent" Width="{Binding Path=Width}" Height="{Binding Path=Height}"  />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Path Stroke="{Binding Path=Stroke}" StrokeThickness="{Binding Path=Thickness}" Data="{Binding Path=Commands}"/>
                   
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemContainerStyle>
                <Style>
                    <Setter Property="Canvas.Top" Value="0" />
                    <Setter Property="Canvas.Left" Value="0" />
                </Style>
            </ItemsControl.ItemContainerStyle>
        </ItemsControl>
                
        <Path Stroke="{Binding Path=Scale.Stroke}" StrokeThickness="{Binding Path=Scale.StrokeThickness}">
            <Path.Data>
                <PathGeometry>
                    <PathGeometry.Figures>
                        <PathFigureCollection>
                            <PathFigure StartPoint="{Binding Path=ScaleBeginOuter}">
                                <PathFigure.Segments>
                                    <ArcSegment Point="{Binding Path=ScaleEndOuter}" Size="{Binding Path=Scale.Size}" RotationAngle="0" IsLargeArc="{Binding Path=IsLargeArc}" SweepDirection="Clockwise" ></ArcSegment>
                                </PathFigure.Segments>
                            </PathFigure>
                        </PathFigureCollection>
                    </PathGeometry.Figures>
                </PathGeometry>
            </Path.Data>
        </Path>
        
        <Line x:Name="_scaleBeginBoundary" StrokeEndLineCap="Round" 
              StrokeThickness="{Binding Path=Scale.StrokeThickness}"
              Stroke="{Binding Path=Scale.Stroke}" 
              X1="{Binding Path=CenterPoint.X}" 
              Y1="{Binding Path=CenterPoint.Y}"
              X2="{Binding Path=ScaleBeginOuter.X}"
              Y2="{Binding Path=ScaleBeginOuter.Y}"
              ></Line>
        
        <Line x:Name="_scaleEndBoundary" StrokeEndLineCap="Round" 
              StrokeThickness="{Binding Path=Scale.StrokeThickness}"
              Stroke="{Binding Path=Scale.Stroke}" 
              X1="{Binding Path=CenterPoint.X}" 
              Y1="{Binding Path=CenterPoint.Y}"
              X2="{Binding Path=ScaleEndOuter.X}"
              Y2="{Binding Path=ScaleEndOuter.Y}"></Line>
        <ItemsControl ItemsSource="{Binding Path=Scale.Ticks}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas  Background="Transparent" Width="{Binding Path=Width}" Height="{Binding Path=Height}"></Canvas>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Line X1="{Binding Path=First.X}" Y1="{Binding Path=First.Y}" X2="{Binding Path=Second.X}" Y2="{Binding Path=Second.Y}" Stroke="{Binding Path=Stroke}" StrokeThickness="{Binding Path=StrokeThickness}"  />

                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
        <ItemsControl ItemsSource="{Binding Path=Scale.Labels}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas Background="Transparent" Width="{Binding Path=Width}" Height="{Binding Path=Height}"></Canvas>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock Foreground="{Binding Path=Stroke}" Text="{Binding Path=Text}"></TextBlock>
                    
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemContainerStyle>
                <Style>
                    <Setter Property="Canvas.Top" Value="{Binding Path=Location.Y}" />
                    <Setter Property="Canvas.Left" Value="{Binding Path=Location.X}" />
                </Style>
            </ItemsControl.ItemContainerStyle>
        </ItemsControl>
        
        <ItemsControl ItemsSource="{Binding Path=Captions}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas Background="Transparent" Width="{Binding Path=Width}" Height="{Binding Path=Height}"  />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock TextAlignment="Center" Text="{Binding Path=Text}" Foreground="{Binding Path=Foreground}" FontSize="{Binding Path=Size}" ></TextBlock>

                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemContainerStyle>
                <Style>
                    <Setter Property="Canvas.Top" Value="{Binding Path=Y,PresentationTraceSources.TraceLevel=High}" />
                    <Setter Property="Canvas.Left" Value="{Binding Path=X,PresentationTraceSources.TraceLevel=High}" />
                </Style>
            </ItemsControl.ItemContainerStyle>
        </ItemsControl>
        <Border BorderBrush="{Binding BezelBackground}" BorderThickness="{Binding BezelThickness}" CornerRadius="{Binding BezelCornerRadius}">
            <Border.Effect>
                <DropShadowEffect Direction="320" Opacity="0.5" ShadowDepth="3" Color="Black"></DropShadowEffect>
            </Border.Effect>
        </Border>
        <Line x:Name="_needle" StrokeEndLineCap="Round" Stroke="{Binding Path=NeedleBrush}" StrokeThickness="{Binding Path=NeedleThickness}" X1="{Binding Path=CenterPoint.X}" Y1="{Binding Path=CenterPoint.Y}" X2="{Binding Path=NeedleEndPoint.X}" Y2="{Binding Path=NeedleEndPoint.Y}" >
            <Line.Effect>
                <DropShadowEffect Direction="320" Opacity="0.5" ShadowDepth="5" Color="Black"></DropShadowEffect>
            </Line.Effect>
        </Line>
        <local:CenteredEllipse x:Name="_needleBase" 
                               Fill="{Binding Path=NeedleBase}" 
                               Center="{Binding Path=CenterPoint}" 
                               RadiusY="{Binding Path=NeedleBaseRadius}" 
                               RadiusX="{Binding Path=NeedleBaseRadius}" >

            <local:CenteredEllipse.Effect>
                <DropShadowEffect Direction="320" Opacity="0.5" ShadowDepth="5" Color="Black"></DropShadowEffect>
            </local:CenteredEllipse.Effect>
        </local:CenteredEllipse>

        
       

    </Grid>
</UserControl>
